<?php

// +----------------------------  用户相关路由 ------------------------------------------

use app\middleware\Check;
use think\facade\Route;

Route::group("user", function () {
    // 用户注册，接收参数：邮箱地址，用户名，密码，验证码
    Route::post("register", "UserController/register");

    // 用户登录，接收参数：邮箱地址，密码
    Route::post("login", "UserController/login");

    // 用户找回密码
    Route::post("findPassword", "UserController/resetPassword");

    // 测试Token接口，接收参数：token
    Route::get("needTokenTest", "UserController/needTokenTest")->middleware(Check::class);

    // 检查用户是否收藏商品，接收参数：user_id, goods_id
    Route::get("checkCollect/:userId/:goodsId", "UserController/checkUserCollection")
        ->pattern([
            'userId'  => '\w+',        // 允许字母、数字、下划线
            'goodsId' => '[\w\.\-]+'    // 允许字母、数字、下划线、短横线
        ]);;

    // 新增收货地址
    Route::post("addAddress", "UserController/addAddress");

    // 获取用户收货地址列表，接收参数：user_id
    Route::get("getAddressList/:userId", "UserController/getUserAddress");



    // 获取用户收藏的商品信息，接收参数：user_id
    Route::get("getCollections/:userId", "UserController/getUserCollections");


    // +++++++++++++管理端+++++++++++++
    // 管理端登录验证，接收参数：用户名，密码
    Route::post("adminLogin", "UserController/authInfo");

    
});


Route::group("user_manage", function () {
    // 用户列表
    Route::post('users', 'UserController/index');

    // 获取指定用户
    Route::get('users/:id', 'UserController/read');

    // 添加用户
    Route::post('addUsers', 'UserController/saveMana');

    // 更新用户
    Route::put('users/:id', 'UserController/update');

    // 更改用户状态
    Route::put('opsUsers/:id/status/:status', 'UserController/changeStatus');

})->middleware(Check::class);
